<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改合作伙伴')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content" >
		<form class="form-horizontal m" id="form-partner-edit" th:object="${partner}">
			<input id="partnerId" name="partnerId" type="hidden" th:field="*{partnerId}"/>
			<div class="form-group">
				<label class="col-sm-3 control-label">合作伙伴名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="partnerName" id="partnerName" required th:field="*{partnerName}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label ">logo：</label>
				<div class="col-sm-8">
					<input id="filePath" name="filePath" class="form-control" type="file">
					<img style="width:50px;height:50px;"  th:src="*{partnerLogo}"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">网站地址：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="partnerNet" id="partnerNet" required th:field="*{partnerNet}">
				</div>
			</div>

		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "user/partner";

		$("#form-post-add").validate({
			onkeyup: false,
			rules:{
				partnerNet:{
					remote: {
						url: prefix +"/checkNet",
						type: "post",
						dataType: "json",
						data: {
							"partnerNet" : function() {
								return $.common.trim($("#partnerNet").val());
							}
						},
						dataFilter: function(data, type) {
							return $.validate.unique(data);
						}
					}
				},
				postSort:{
					digits:true
				},
			},
			messages: {
				"partnerNet": {
					remote: "网址已经存在"
				}
			},
			focusCleanup: true
		});

		//文件上传下载
		function submitHandler() {
			if ($.validate.form()) {
				uploadFile();
			}
		}
		function uploadFile() {
			var formData = new FormData();
			if ($('#filePath')[0].files[0] == null) {
				$.modal.alertWarning("请先选择文件路径");
				return false;
			}
			formData.append('fileName', $("#fileName").val());
			formData.append('partnerId', $("#partnerId").val());
			formData.append('file', $('#filePath')[0].files[0]);
			formData.append('partnerName',$('#partnerName').val());
			formData.append('partnerNet',$('#partnerNet').val());
			$.ajax({
				url: prefix + "/edit",
				type: 'post',
				cache: false,
				data: formData,
				processData: false,
				contentType: false,
				dataType: "json",
				success: function(result) {
					$.operate.successCallback(result);
				}
			});
		}

	</script>
</body>
</html>
